package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.ReservationServiceRel;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReservationServiceRelMapper {

	/**
	 * 查询所有关联信息
	 *
	 * @return 关联列表
	 */
	@Select("SELECT * FROM reservation_service_rel")
	List<ReservationServiceRel> selectAllReservationServiceRels();

	/**
	 * 根据关联ID查询关联信息
	 *
	 * @param relId 关联ID
	 * @return 匹配的关联对象
	 */
	@Select("SELECT * FROM reservation_service_rel WHERE rel_id = #{relId}")
	ReservationServiceRel selectReservationServiceRelById(@Param("relId") Integer relId);

	/**
	 * 根据预约订单ID查询关联信息
	 *
	 * @param orderId 预约订单ID
	 * @return 匹配的关联列表
	 */
	@Select("SELECT * FROM reservation_service_rel WHERE order_id = #{orderId}")
	List<ReservationServiceRel> selectReservationServiceRelByOrderId(@Param("orderId") Integer orderId);

	/**
	 * 插入新的关联信息
	 *
	 * @param reservationServiceRel 新关联的信息
	 */
	@Insert("INSERT INTO reservation_service_rel(order_id, service_type_id) VALUES(#{orderId}, #{serviceTypeId})")
	@Options(useGeneratedKeys = true, keyProperty = "relId")
	void insertReservationServiceRel(ReservationServiceRel reservationServiceRel);

	/**
	 * 更新已有关联的信息
	 *
	 * @param reservationServiceRel 需要更新的关联信息
	 */
	@Update("UPDATE reservation_service_rel SET order_id=#{orderId}, service_type_id=#{serviceTypeId} WHERE rel_id=#{relId}")
	void updateReservationServiceRel(ReservationServiceRel reservationServiceRel);

	/**
	 * 删除指定ID的关联
	 *
	 * @param relId 关联ID
	 */
	@Delete("DELETE FROM reservation_service_rel WHERE rel_id = #{relId}")
	void deleteReservationServiceRelById(@Param("relId") Integer relId);
}